/*
 *  ifxcommand.hpp - Informix dbExpress command class
 *
 *    Copyright (c) 2001-2006, Luxena Software Company. All rights reserved.
 *
 *  Purpose:
 *
 */

#ifndef __IFXCOMMAND_HPP__
#define __IFXCOMMAND_HPP__

#ifndef __cplusplus
#error This header requires a C++ compiler ...
#endif

#include <ifxtypes.h>
#include <sqlhdr.h>
#include "dbxpress.hpp"
#include "dbxcommon.hpp"
#include "ifxconnection.hpp"
#include "ifxparams.hpp"


/////////////////////////////////////////////////////////////////////////////
// CInformixCommand - SQLCommand implementation for Informix

class CInformixCommand : public CErrorHandlingImpl< CUnknownImpl<SQLCommand> >,
	private IDatabaseChangeObserver
{
public:
	CInformixCommand (CInformixConnection *connection);
	virtual ~CInformixCommand ();

	CInformixConnection * getConnection ();
	CCallback * getCallback ();
	int4 getBlobSize ();
	ifx_cursor_t * getHandle ();
	CInformixParameters& getParameters ();
	bool isPrepared ();
	virtual void setErrorMessage (const char* errorMessage);

// SQLCommand
public:
	SQL_METHOD setOption (eSQLCommandOption eSOption, INT32 lValue);
	SQL_METHOD getOption (eSQLCommandOption eSOption, pINT32 plValue, INT16 iMaxLength, pINT16 piLength);
	SQL_METHOD setParameter (UINT16 uParameterNumber, UINT16 uChildPos, STMTParamType ePType, UINT16 uLogType, UINT16 uSubType, INT32 lMaxPrecision, INT32 lMaxScale, UINT32 ulLength, pVOID pBuffer, BOOL bIsNull);
	SQL_METHOD getParameter (UINT16 uParameterNumber, UINT16 uChildPos, pVOID pData, UINT32 ulLength, pINT32 plInd);
	SQL_METHOD prepare (pCHAR pszSQL, UINT16 uParamCount);
	SQL_METHOD execute (ppSQLCursor ppCur);
	SQL_METHOD executeImmediate (pCHAR pszSQL, ppSQLCursor ppCur);
	SQL_METHOD getNextCursor (ppSQLCursor ppCur);
	SQL_METHOD getRowsAffected (pINT32 plRows);
	SQL_METHOD close ();

private:
	void setResourceDefaults ();
	void freeResources ();
	bool isDatabaseChangingStatement(int2 stmtType);

	CInformixConnection *_connection;
	CInformixParameters *_parameters;
	int4 _rowsAffected;

	                             // dbExpress command options
	                             // _________________________
	                             //
	int4 _rowsetSize;            // eCommRowsetSize
	int4 _blobSize;              // eCommBlobSize
	bool _blockRead;             // eCommBlockRead
	ifx_cursor_t *_handle;       // eCommNativeHandle
	bool _storedProc;            // eCommStoredProc

// IDatabaseChangeObserver
	virtual void databaseChanged ();
};

#endif // __IFXCOMMAND_HPP__
